// src/shared/service/systemService.ts

import { Banner, ApiResponse } from '../types';
import { STORAGE_KEYS, getStorageData } from '../utils/storage';

// ===== 轮播图功能 =====

export interface BannerListResponse {
  banners: Banner[];
}

/**
 * 获取轮播图列表
 */
export const getBanners = async (): Promise<ApiResponse<BannerListResponse>> => {
  try {
    // 获取轮播图数据
    const banners = getStorageData<Banner>(STORAGE_KEYS.BANNERS);

    // 按排序权重排序（sort字段越小越靠前）
    const sortedBanners = banners.sort((a, b) => a.sort - b.sort);

    return {
      code: 200,
      message: '获取轮播图列表成功',
      data: {
        banners: sortedBanners
      }
    };

  } catch (error) {
    console.error('获取轮播图列表失败:', error);
    return {
      code: 500,
      message: '服务器内部错误',
      data: null
    };
  }
};